package com.common.DAO;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.common.entity.Path;
import com.common.entity.Step;

public class StepDAO extends BaseDAO implements IStepDAO {

	@Override
	public void addStep(Step step){
		logger.info("AddStep()");
		try{
			super.save(step);
		}catch (Exception e) {
			logger.error("erreur in DAO while adding a step. erreur : "+e);
		}
		logger.info("addStep() done");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Step> listStepsByPath(int id_path){
		try{
			List<Step> steps = super.list("from Step where path="+id_path);
			return steps;
		}catch (Exception e) {
			logger.error("erreur requete",e);
		}
		return null;
	}
	
	/**************************************************************************
	 * Remove path															  *
	 * @param int id of removing path                                        *
	 * @return anything                                                       *
	 **************************************************************************/
	@SuppressWarnings("unchecked")
	@Override
	public void removeStepByPath(int id){
		logger.info("removeStep");
		HibernateTemplate hibernateTemplate = super.getHibernateTemplate();
		List<Step> steps=hibernateTemplate.find("from Step where path='"+id+"'");
		for(Step step : steps){
			hibernateTemplate.delete(step);
		}
		logger.info("removeStep() done");
	}
}
